<?php

abstract class View {
    private $_data = [];
    private $_controller = null;
    protected $_velden = null;
    
    public function __construct($controller=null) {
        $this->_controller = $controller;
        $this->_velden = new \Velden();
    }
    
    public function setData($sleutel='',$waarde='') {
        $sleutel = trim($sleutel);
        if (!empty($sleutel)) {
            $sleutel = strtolower($sleutel);
            $this->_data[$sleutel] = $waarde;
        }
    }
    
    public function getData($sleutel='') {
        $sleutel = trim($sleutel);
        if (!empty($sleutel)) {
            $sleutel = strtolower($sleutel);
            if (array_key_exists($sleutel,$this->_data)) {
                return $this->_data[$sleutel];
            } else {
                return '';
            }
        }
    }
    
    public function genereer($module='',$controller='',$actie='') {
        $padView = explode(DIRECTORY_SEPARATOR,realpath(dirname(__FILE__)));
        array_pop($padView);
        $padView = implode(DIRECTORY_SEPARATOR,array_merge($padView,['modules',$module,'Views',$controller,$actie.'.php']));
        if (file_exists($padView) && is_readable($padView)) { 
            require_once($padView);
        }
    }
}
